package com.heima.controller;

import com.heima.common.PageResult;
import com.heima.pojo.Region;
import com.heima.pojo.dto.RegionDTO;
import com.heima.pojo.dto.RegionPageQueryDTO;
import com.heima.service.RegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/region")
@Slf4j
public class RegionController {

    @Autowired
    private RegionService regionService;

    /**
     * 分页查询区域
     * @param dto
     * @return
     */
    @GetMapping("/search")
    public PageResult pageQuery(RegionPageQueryDTO dto){
        PageResult pageResult = regionService.pageQuery(dto);
        return pageResult;
    }

    /**
     * 新增区域
     * @param regionDTO
     * @return
     */
    @PostMapping
    public Boolean insert(@RequestBody RegionDTO regionDTO){
        regionService.insert(regionDTO);
        return true;
    }

    /**
     * 修改区域
     * @param regionId
     * @param regionDTO
     * @return
     */
    @PutMapping("/{regionId}")
    public Boolean update(@PathVariable Long regionId,@RequestBody RegionDTO regionDTO){
        regionService.update(regionId,regionDTO);
        return true;
    }

    @DeleteMapping("/{regionId}")
    public Boolean delete(@PathVariable Long regionId){
        regionService.delete(regionId);
        return true;
    }

}
